/*
 *  LineFactory.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/06/29.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "LineFactory.h"
#include "Line.h"
#include "NullLine.h"

namespace sc
{
	std::set<StraightLine> LineFactory::straightLines;

	std::set<ConvexParabola> LineFactory::convexParabolas;

	std::set<ConcateParabola> LineFactory::concateParabolas;

	const Line& LineFactory::Create( Line::Type type, double startX, double startY, double endX, double endY )
	{
		switch ( type )
		{
		case Line::Type_Straight:
			{
				std::pair< std::set< StraightLine >::iterator, bool > res = 
					straightLines.insert( StraightLine( startX, startY, endX, endY ) );
				return (*res.first);
			}
		case Line::Type_ConvexParabola:
			{
				std::pair< std::set< ConvexParabola >::iterator, bool > res = 
					convexParabolas.insert( ConvexParabola( startX, startY, endX, endY ) );
				return (*res.first);
			}
		case Line::Type_ConcateParabola:
			{
				std::pair< std::set< ConcateParabola >::iterator, bool > res = 
					concateParabolas.insert( ConcateParabola( startX, startY, endX, endY ) );
				return (*res.first);
			}
		case Line::Type_Null:
		default:
			return NullLine::GetInstance();
		}
	}

	void LineFactory::DisposeInstance()
	{
		straightLines.clear();
		convexParabolas.clear();
		concateParabolas.clear();
	}
}